package cn.humaohua.study.yanmo_design_pattern.ch20;

import java.util.HashMap;
import java.util.Map;

public class FlyweightFactory {
    private static FlyweightFactory instance = new FlyweightFactory();

    private static Map<String, Flyweight> cache = new HashMap<>();

    private FlyweightFactory() {
    }

    public static FlyweightFactory getInstance() {
        return instance;
    }

    public Flyweight getFlyweight(String key) {
        Flyweight f = cache.get(key);
        if (f == null) {
            f = new AuthorizationFlyweight(key);
            cache.put(key, f);
        }
        return f;
    }
}
